﻿// Decompiled with JetBrains decompiler
// Type: StoryMode.CampaignStoryMode
// Assembly: StoryMode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 11BAE65F-6C15-4628-A9C6-1B968588CDA1
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\StoryMode\bin\Win64_Shipping_Client\StoryMode.dll

using System.Collections.Generic;
using TaleWorlds.CampaignSystem;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace StoryMode
{
  public class CampaignStoryMode : Campaign
  {
    [SaveableProperty(9999)]
    public StoryModeManager StoryMode { get; private set; }

    public CampaignStoryMode(CampaignGameMode gameMode)
      : base(gameMode)
    {
      this.StoryMode = new StoryModeManager();
    }

    protected override void BeforeRegisterTypes(MBObjectManager objectManager)
    {
      base.BeforeRegisterTypes(objectManager);
      objectManager.RegisterType<TrainingField>("TrainingField", "TrainingFields", 1U);
    }

    protected override void DoLoadingForGameType(
      GameTypeLoadingStates gameTypeLoadingState,
      out GameTypeLoadingStates nextState)
    {
      base.DoLoadingForGameType(gameTypeLoadingState, out nextState);
      if (gameTypeLoadingState == GameTypeLoadingStates.InitializeFirstStep && nextState != gameTypeLoadingState)
        this.StoryMode.InitializeStoryModeObjects();
      if (gameTypeLoadingState == GameTypeLoadingStates.LoadVisualsThirdState && nextState != gameTypeLoadingState)
      {
        Settlement settlement = Settlement.Find("tutorial_training_field");
        if (settlement != null)
          this.MapSceneWrapper.AddNewEntityToMapScene(settlement.StringId, settlement.Position2D);
      }
      if (gameTypeLoadingState != GameTypeLoadingStates.PostInitializeFourthState)
        return;
      this.OnSessionLaunched();
    }

    private void OnSessionLaunched() => this.StoryMode.MainStoryLine.OnSessionLaunched();

    internal static void AutoGeneratedStaticCollectObjectsCampaignStoryMode(
      object o,
      List<object> collectedObjects)
    {
      ((GameType) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.StoryMode);
    }

    internal static object AutoGeneratedGetMemberValueStoryMode(object o)
    {
      return (object) ((CampaignStoryMode) o).StoryMode;
    }
  }
}
